package cn.com.taurus.controller.major;

import cn.com.taurus.biz.AdminsBiz;
import cn.com.taurus.biz.PowerManagerBiz;
import cn.com.taurus.entity.Admins;
import cn.com.taurus.entity.PowerManager;
import cn.com.taurus.util.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Controller
public class AdminsWebController {
    @Autowired
    AdminsBiz adminsBiz;

    public static Integer aId;
    public static String aName;

    @RequestMapping(value = "/selectAdminsWeb")
    @Log(operation = "登录后台",type = 0)
    public ModelAndView selectAdminsWeb(@AuthenticationPrincipal UserDetails userDetails){
        //Controller层可以通过@AuthenticationPrincipal UserDetails userDetails
        //获取登录成功后的用户对象简化版
        ModelAndView modelAndView = new ModelAndView();
        Admins admins = adminsBiz.selectAdmisByAAccount(userDetails.getUsername());

        modelAndView.addObject("adminsData",admins);
        System.err.println(admins.toString());
        this.aId =  admins.getaId();
        this.aName =  admins.getaName();
        modelAndView.setViewName("supermanager/BackgroundHomepage");
        return modelAndView;
    }
}
